package com.trkj.controller;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;

import com.trkj.pojo.Archive;
import com.trkj.pojo.Emp;
import com.trkj.pojo.Yearleave;
import com.trkj.service.EmpService;
import com.trkj.vo.EditeEmpVo;

@Controller
@SessionAttributes({"funcIds"})
public class ControllerOne {

	/**
	 * @author csj
	 */
	@Autowired
	EmpService empService;
	
	/**
	 * 调用档案信息的主界面
	 * @author csj
	 * @return
	 */
	@GetMapping("to_RSarchives")
	public String toRSarchives() {
		return "RSarchives";
	}
	

	/**
	 * 多表分页带条件模糊查询用户信息
	 * @return 
	 * @author csj
	 * @return
	 */
	@RequestMapping("/get_AllEmpInfo")
	public @ResponseBody Map<String, Object> queryEmp(String empName, String empState, String archivesEmptype, Integer page,
			Integer rows,@RequestParam(required=false,defaultValue="empId") String sort,
			@RequestParam(required=false,defaultValue="desc") String order) {
		
		return empService.pageSelect(empName, empState, archivesEmptype, page, rows, sort, order);
	}
	
	/**
	 * 调用添加界面
	 * @author csj
	 * @return
	 */
	@GetMapping("increase")
	public String increase() {
		return "addto_emp";
	}
	
	/**
	 * 调用查看个人信心界面
	 * @author csj
	 * @return
	 */
	@GetMapping("check_emp")
	public String check_emp() {
		return "check_emp";
	}
	
	
	/**
	 * 调用编辑界面
	 * @author csj
	 * @return
	 */
	@GetMapping("edito_emp")
	public String edito_emp() {
		return "edito_emp";
	}
	
	/**
	 * 传输增加一个员工的基本信息和档案信息和年假信息
	 * 
	 * @param emp
	 * @param archive
	 * @param deptId
	 * @param professorId
	 * @param yearleave
	 * @author csj
	 * @return 
	 * @return
	 */
	@RequestMapping("/save_emp")
	@ResponseBody
	public boolean  save_emp( Emp empall, Archive archive,
			@RequestParam("deptId") Integer deptId,
			@RequestParam("professorId") Integer professorId,
			Yearleave yearleave) {
		
		System.out.println(empall.getEmpId());
		
		Integer isSave = empService.save_danAnInfo(empall, deptId, archive, professorId, yearleave);
		if(isSave!=0) {
			return true;
		}
		return false;
	}
	
	/**
	 * 传输获取的id查询出该个人的所有信息
	 * @author csj
	 * @param empId
	 * @return
	 */
	@RequestMapping("editemp")
	@ResponseBody
	public EditeEmpVo editemp(@RequestParam("empId") Integer empId) {
		return empService.editempVo(empId);
	}
	
	
	/**
	 * 传输要修改一个员工的个人信息
	 * @author csj
	 * @param emp
	 * @param archive
	 * @param professorId
	 * @return
	 */
	
	@RequestMapping("/emp_revise")
	@ResponseBody
	public boolean emp_revise(Emp empall,Archive archive,@RequestParam("professorId") Integer professorId) {
		
		Integer revise = empService.revise_Info(empall,archive,professorId);
		if(revise!=0) {
			return true;
		}
		return false;
	}
	
	/**
	 * 传输职称表中的职称信息
	 * @author csj
	 * @return
	 */
	@RequestMapping("/combobox_professor")
	public @ResponseBody List<Map<String, Object>> findAll_professor() {
		return empService.findAll_professor_combobox();
	}
	/**
	 * 传输要查看的档案信息
	 * @author csj
	 * @param empId
	 * @return
	 */
	@RequestMapping("checkemp")
	@ResponseBody
	public EditeEmpVo checkemp(@RequestParam("empId") Integer empId) {
		return empService.checkemp(empId);
	}
	
	
	
	
}
